package com.xiaobawang.xjsyy_idea_plugin.panel.config.view;

import com.xiaobawang.xjsyy_idea_plugin.global.GlobalConfig;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.util.List;

/**
 * @author synhard
 * @description 插件配置 tab
 * @date 2024/5/22 15:01
 * @email songxinhang2023@e-chinalife.com
 * @id 18101119
 * @phone 13001321080
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ConfigPanel extends JPanel {
    // token 的 panel
    private TokenPanel tokenPanel;
    // org 的 panel
    private OrgSelectPanel orgSelectPanel;
    // 代码仓库的 panel
    private GitRepoPanel codeRepoPanel;
    // 应用的 panel
    private AppSelectPanel appSelectPanel;
    public ConfigPanel() {
        setLayout(new GridLayout(4, 1));
        tokenPanel = new TokenPanel();
        add(tokenPanel);
        orgSelectPanel = new OrgSelectPanel();
        add(orgSelectPanel);
        // 仓库链接更新后，刷新应用列表
        codeRepoPanel = new GitRepoPanel(this::refreshAppList);
        add(codeRepoPanel);
        appSelectPanel = new AppSelectPanel();
        add(appSelectPanel);
    }

    // 新增方法用于根据仓库链接刷新应用列表
    private void refreshAppList() {
        GlobalConfig.appNameList.clear();
        if (GlobalConfig.gitRepo.equals("http1")) {
            GlobalConfig.appNameList.add("ipbps-serviceapp");
            GlobalConfig.appNameList.add("ipbps-zookeeper");
            // app 默认选取第一个
            GlobalConfig.appName = "ipbps-serviceapp";
        } else if (GlobalConfig.gitRepo.equals("http2")) {
            GlobalConfig.appNameList.add("ipbps-rabbitmq");
            GlobalConfig.appNameList.add("ipbps-kafka");
            // app 默认选取第一个
            GlobalConfig.appName = "ipbps-rabbitmq";
        }
        appSelectPanel.refreshAppList(GlobalConfig.appNameList);
    }
}
